package nc.vo.erm.matterapp;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import nc.vo.annotation.AggVoInfo;
import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.pub.CircularlyAccessibleValueObject;
import nc.vo.pub.ISuperVO;
import nc.vo.pub.IVOMeta;
import nc.vo.pub.SuperVO;
import nc.vo.pubapp.pattern.model.entity.bill.IBill;
import nc.vo.pubapp.pattern.model.meta.entity.bill.BillMetaFactory;
import nc.vo.pubapp.pattern.model.meta.entity.bill.IBillMeta;
import nc.vo.trade.pub.HYBillVO;
import nc.vo.trade.pub.IExAggVO;


@AggVoInfo(parentVO="nc.vo.erm.matterapp.MatterAppVO")
public class AggMatterAppVO extends HYBillVO implements Cloneable, IExAggVO, IBill {
  private AggMatterAppVO oldvo;
  private static String[] headYbAmounts;
  private static String[] headOrgAmounts;
  private static String[] headGroupAmounts;
  private static String[] headGlobalAmounts;
  private static String[] bodyYbAmounts;
  private static String[] bodyOrgAmounts;
  private static String[] bodyGroupAmounts;
  private static String[] bodyGlobalAmounts;
  private static String[] headAmounts;
  private static String[] bodyAmounts;
  private static List<String> applyOrgHeadIterms;
  private static List<String> applyOrgBodyIterms;
  private static List<String> bodyAssumeOrgBodyIterms;
  private static List<String> notRepeatFields;
  private static String[] fieldNotCopy;
  private static String[] childFieldNotCopy;
  public static String[] excelInputHeadItems = { "pk_tradetype", "billdate", "pk_org", "pk_currtype", "orig_amount", "apply_org", "apply_dept", "billmaker", "billno" };
  


  public static String[] excelInputBodyItems = { "assume_org", "assume_dept", "orig_amount" };
  

  static
  {
    headAmounts = new String[] { "orig_amount", "rest_amount", "exe_amount", "org_amount", "org_exe_amount", "org_rest_amount", "group_amount", "group_rest_amount", "group_exe_amount", "global_amount", "global_rest_amount", "global_exe_amount" };
    



    bodyAmounts = new String[] { "orig_amount", "rest_amount", "exe_amount", "org_amount", "org_rest_amount", "org_exe_amount", "group_amount", "group_exe_amount", "group_rest_amount", "global_amount", "global_exe_amount", "global_rest_amount", "usable_amout" };
    




    headYbAmounts = new String[] { "orig_amount", "rest_amount", "exe_amount", "pre_amount", "max_amount" };
    

    headOrgAmounts = new String[] { "org_amount", "org_exe_amount", "org_rest_amount", "org_pre_amount" };
    

    headGroupAmounts = new String[] { "group_amount", "group_rest_amount", "group_exe_amount", "group_pre_amount" };
    

    headGlobalAmounts = new String[] { "global_amount", "global_rest_amount", "global_exe_amount", "global_pre_amount" };
    

    bodyYbAmounts = new String[] { "orig_amount", "rest_amount", "exe_amount", "pre_amount", "usable_amout", "max_amount", "apply_amount" };
    


    bodyOrgAmounts = new String[] { "org_amount", "org_rest_amount", "org_exe_amount", "org_pre_amount" };
    

    bodyGroupAmounts = new String[] { "group_amount", "group_exe_amount", "group_rest_amount", "group_pre_amount" };
    

    bodyGlobalAmounts = new String[] { "global_amount", "global_exe_amount", "global_rest_amount", "global_pre_amount" };
    

    fieldNotCopy = new String[] { "approver", "approvetime", "pk_mtapp_bill", "billno", "billstatus", "effectstatus", "apprstatus", "modifier", "modifiedtime", "closeman", "closedate", "printer", "printdate", "creator", "creationtime", "exe_amount", "org_exe_amount", "group_exe_amount", "global_exe_amount", "pre_amount", "org_pre_amount", "group_pre_amount", "global_pre_amount", "ts" };
    






    childFieldNotCopy = new String[] { "effectstatus", "pk_mtapp_detail", "billno", "billstatus", "close_status", "closedate", "exe_amount", "org_exe_amount", "group_exe_amount", "global_exe_amount", "pk_mtapp_detail", "pre_amount", "org_pre_amount", "group_pre_amount", "global_pre_amount", "closedate", "closeman", "rowno" };
    





    applyOrgHeadIterms = new ArrayList();
    

    applyOrgHeadIterms.add("reason");
    applyOrgHeadIterms.add("pk_customer");
    applyOrgHeadIterms.add("assume_dept");
    
    applyOrgBodyIterms = new ArrayList();
    applyOrgBodyIterms.add("reason");
    
    bodyAssumeOrgBodyIterms = new ArrayList();
    bodyAssumeOrgBodyIterms.add("assume_dept");
    
    bodyAssumeOrgBodyIterms.add("pk_salesman");
    bodyAssumeOrgBodyIterms.add("pk_iobsclass");
    bodyAssumeOrgBodyIterms.add("pk_project");
    bodyAssumeOrgBodyIterms.add("pk_wbs");
    bodyAssumeOrgBodyIterms.add("pk_customer");
    bodyAssumeOrgBodyIterms.add("pk_supplier");
    
    notRepeatFields = new ArrayList();
    notRepeatFields.add("pk_pcorg");
    notRepeatFields.add("pk_resacostcenter");
    notRepeatFields.add("pk_iobsclass");
    notRepeatFields.add("pk_project");
    notRepeatFields.add("pk_wbs");
    
    notRepeatFields.add("pk_customer");
    notRepeatFields.add("pk_checkele");
    notRepeatFields.add("pk_supplier");
    notRepeatFields.add("pk_salesman");
    
    notRepeatFields.add("assume_org");
    notRepeatFields.add("assume_dept");
    
    notRepeatFields.add("pk_proline");
    notRepeatFields.add("pk_brand");
  }
  




  public static String[] getBodyMultiSelectedItems()
  {
    return new String[] { "assume_org", "assume_dept", "pk_iobsclass", "pk_pcorg", "pk_resacostcenter", "pk_checkele", "pk_project", "pk_customer", "pk_supplier", "pk_wbs", "pk_salesman", "pk_brand", "pk_proline" };
  }
  



  public Object clone()
  {
    AggMatterAppVO aggVo = new AggMatterAppVO();
    
    if (getParentVO() != null) {
      aggVo.setParentVO((MatterAppVO)getParentVO().clone());
    }
    
    String[] allTabcodes = getAllTabcodes();
    for (int i = 0; i < allTabcodes.length; i++) {
      CircularlyAccessibleValueObject[] cvos = getTableVO(allTabcodes[i]);
      if (cvos != null) {
        CircularlyAccessibleValueObject[] clonevos = new CircularlyAccessibleValueObject[cvos.length];
        for (int j = 0; j < cvos.length; j++) {
          if (cvos[j] != null) {
            clonevos[j] = ((CircularlyAccessibleValueObject)cvos[j].clone());
          }
        }
        aggVo.setTableVO(allTabcodes[i], clonevos);
      }
    }
    
    return aggVo;
  }
  
  public void setChildrenVO(CircularlyAccessibleValueObject[] children)
  {
    setTableVO(getTableCodes()[0], children);
  }
  


  public MatterAppVO getParentVO()
  {
    return (MatterAppVO)super.getParentVO();
  }
  
  public MtAppDetailVO[] getChildrenVO() {
    CircularlyAccessibleValueObject[] tableVO = getTableVO(getTableCodes()[0]);
    if ((tableVO == null) || (tableVO.length == 0)) {
      return null;
    }
    MtAppDetailVO[] childs = new MtAppDetailVO[tableVO.length];
    System.arraycopy(tableVO, 0, childs, 0, tableVO.length);
    return childs;
  }
  
  public static String[] getHeadYbAmounts() {
    return headYbAmounts;
  }
  
  public static String[] getHeadGroupAmounts() {
    return headGroupAmounts;
  }
  
  public static String[] getHeadGlobalAmounts() {
    return headGlobalAmounts;
  }
  
  public static String[] getHeadOrgAmounts() {
    return headOrgAmounts;
  }
  
  public static String[] getBodyYbAmounts() {
    return bodyYbAmounts;
  }
  
  public static String[] getBodyOrgAmounts() {
    return bodyOrgAmounts;
  }
  
  public static String[] getBodyGroupAmounts() {
    return bodyGroupAmounts;
  }
  
  public static String[] getBodyGlobalAmounts() {
    return bodyGlobalAmounts;
  }
  
  public static String[] getHeadAmounts() {
    return headAmounts;
  }
  
  public static String[] getBodyAmounts() {
    return bodyAmounts;
  }
  
  public static List<String> getApplyOrgHeadIterms() {
    return applyOrgHeadIterms;
  }
  
  public static List<String> getApplyOrgBodyIterms() {
    return applyOrgBodyIterms;
  }
  
  public static List<String> getNotRepeatFields() {
    return notRepeatFields;
  }
  

  private HashMap hmChildVOs = new HashMap();
  






  public String[] getTableCodes()
  {
    return new String[] { "mtapp_detail" };
  }
  






  public String[] getTableNames()
  {
    return new String[] { NCLangRes4VoTransl.getNCLangRes().getStrByID("201212_0", "0201212-0094") };
  }
  









  public String[] getAllTabcodes()
  {
    return (String[])this.hmChildVOs.keySet().toArray(new String[this.hmChildVOs.keySet().size()]);
  }
  




  public String[] getAllExtendTabcodes()
  {
    String[] alltabcodes = getAllTabcodes();
    List<String> list = new ArrayList();
    list.addAll(Arrays.asList(alltabcodes));
    
    String[] tableCodes = getTableCodes();
    for (int i = 0; i < tableCodes.length; i++) {
      list.remove(tableCodes[i]);
    }
    return (String[])list.toArray(new String[list.size()]);
  }
  






  public CircularlyAccessibleValueObject[] getAllChildrenVO()
  {
    ArrayList al = new ArrayList();
    String[] allTabcodes = getAllTabcodes();
    for (int i = 0; i < allTabcodes.length; i++) {
      CircularlyAccessibleValueObject[] cvos = getTableVO(allTabcodes[i]);
      if (cvos != null) {
        al.addAll(Arrays.asList(cvos));
      }
    }
    return (SuperVO[])al.toArray(new SuperVO[0]);
  }
  





  public CircularlyAccessibleValueObject[] getTableVO(String tableCode)
  {
    return (CircularlyAccessibleValueObject[])this.hmChildVOs.get(tableCode);
  }
  




















  public void setTableVO(String tableCode, CircularlyAccessibleValueObject[] vos)
  {
    this.hmChildVOs.put(tableCode, vos);
  }
  





  public String getDefaultTableCode()
  {
    return getTableCodes()[0];
  }
  










  public SuperVO[] getChildVOsByParentId(String tableCode, String parentId)
  {
    return null;
  }
  






  public HashMap getHmEditingVOs()
    throws Exception
  {
    return null;
  }
  








  public String getParentId(SuperVO item)
  {
    return null;
  }
  
  public ISuperVO[] getChildren(Class<? extends ISuperVO> clazz)
  {
    return getChildrenVO();
  }
  
  public ISuperVO[] getChildren(IVOMeta childMeta) {
	  IVOMeta bodyvo = new MtAppDetailVO().getMetaData();
	  IVOMeta fjvo = new MtAppDetail1VO().getMetaData();
	  if(childMeta == bodyvo){
		  return (MtAppDetailVO[]) this.hmChildVOs.get("mtapp_detail");
	  } else if(childMeta == fjvo){
		  return (MtAppDetail1VO[]) this.hmChildVOs.get("mtapp_detail1");
	  }
	  return null;
  }
  
  public ISuperVO getParent()
  {
    return getParentVO();
  }
  
  public String getPrimaryKey()
  {
    return getParentVO().getPrimaryKey();
  }
  














  public IBillMeta getMetaData()
  {
    IBillMeta billMeta = BillMetaFactory.getInstance().getBillMeta("erm.mtapp_bill");
    return billMeta;
  }
  
  public static List<String> getBodyAssumeOrgBodyIterms() {
    return bodyAssumeOrgBodyIterms;
  }
  
  public static void setBodyAssumeOrgBodyIterms(List<String> bodyAssumeOrgBodyIterms) {
    bodyAssumeOrgBodyIterms = bodyAssumeOrgBodyIterms;
  }
  






  public String getVoucherKey()
  {
    MatterAppVO vo = getParentVO();
    MtAppDetailVO[] detailvos = getChildrenVO();
    String pk_pcorg = null;
    if ((detailvos != null) && (detailvos.length > 0)) {
      pk_pcorg = detailvos[0].getPk_pcorg();
    }
    if (vo.getClose_status().intValue() == 2) {
      return vo.getPk_mtapp_bill() + pk_pcorg + vo.getBilldate().toStdString();
    }
    
    return vo.getPk_mtapp_bill() + pk_pcorg;
  }
  
  public AggMatterAppVO getOldvo()
  {
    return this.oldvo;
  }
  
  public void setOldvo(AggMatterAppVO oldvo) {
    this.oldvo = oldvo;
  }
  
  public static String[] getFieldNotCopy() {
    return fieldNotCopy;
  }
  
  public static void setFieldNotCopy(String[] fieldNotCopy) {
    fieldNotCopy = fieldNotCopy;
  }
  
  public static String[] getChildFieldNotCopy() {
    return childFieldNotCopy;
  }
  
  public static void setChildFieldNotCopy(String[] childFieldNotCopy) {
    childFieldNotCopy = childFieldNotCopy;
  }
  
  public AggMatterAppVO() {}
  
  public void setParentId(SuperVO item, String id) {}
  
  public void setChildren(Class<? extends ISuperVO> clazz, ISuperVO[] vos) {}
  
  public void setChildren(IVOMeta childMeta, ISuperVO[] items) {
	  IVOMeta mxmate = new MtAppDetailVO().getMetaData();
	  IVOMeta fjmate = new MtAppDetail1VO().getMetaData();
	  if(childMeta == mxmate){
		  this.hmChildVOs.put("mtapp_detail", items);
	  } else if(childMeta == fjmate){
		  this.hmChildVOs.put("mtapp_detail1", items);
	  }
  }
  
  public void setParent(ISuperVO parent) {}
}